parameters:
  name: ''

steps:
- task: PublishTestResults@2
  displayName: Publish Test Results
  inputs:
    testResultsFormat: 'VSTest'
    testResultsFiles: '*.trx'
    searchFolder: '$(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)'
    mergeTestResults: true
    testRunTitle: Installer-${{ parameters.name }}-$(_BuildConfig)
  continueOnError: true
  condition: always()

# Upload binaries and symbols on failure to allow debugging issues
- task: CopyFiles@2
  displayName: Prepare binaries to publish
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)/artifacts/bin'
    Contents: |
      */corehost/**
      */corehost_test/**
    TargetFolder: '$(Build.StagingDirectory)/Binaries'
  continueOnError: true
  condition: failed()

- task: ArchiveFiles@2
  displayName: Zip binaries
  inputs:
    rootFolderOrFile: '$(Build.StagingDirectory)/Binaries'
    archiveFile: '$(Build.StagingDirectory)/corehost-bin-${{ parameters.name }}-$(_BuildConfig)$(archiveExtension)'
    archiveType: $(archiveType)
    tarCompression: $(tarCompression)
    includeRootFolder: false
  continueOnError: true
  condition: failed()

- task: PublishBuildArtifacts@1
  displayName: Publish binaries
  inputs:
    pathtoPublish: '$(Build.StagingDirectory)/corehost-bin-${{ parameters.name }}-$(_BuildConfig)$(archiveExtension)'
    artifactName: Installer-Binaries-${{ parameters.name }}-$(_BuildConfig)
  continueOnError: true
  condition: failed()

- task: CopyFiles@2
  displayName: Prepare BuildLogs staging directory
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: |
      **/*.log
      **/*.binlog
    TargetFolder: '$(Build.StagingDirectory)/BuildLogs'
    CleanTargetFolder: true
  continueOnError: true
  condition: always()

- task: PublishPipelineArtifact@1
  displayName: Publish BuildLogs
  inputs:
    targetPath: '$(Build.StagingDirectory)/BuildLogs'
    artifactName: Installer-Logs_Attempt$(System.JobAttempt)-${{ parameters.runtimeFlavor }}-${{ parameters.runtimeVariant }}-${{ parameters.name }}-$(_BuildConfig)
  continueOnError: true
  condition: always()
